<?php
namespace app\common\exception;

use Exception;
use think\exception\Handle;
use think\exception\ErrorException;
use think\exception\PDOException;
use think\exception\ThrowableError;

class ExceptionHandler extends Handle
{
    public function render(Exception $e)
    {
        if ($e instanceof ErrorException) {
            header('Content-Type:application/json; charset=utf-8');
            exit(json_encode(['data' => 'error错误', 'code' => config('code.common.error')]));
        }
        if ($e instanceof PDOException) {
            header('Content-Type:application/json; charset=utf-8');
            exit(json_encode(['data' => 'pdo错误', 'code' => config('code.common.error')]));
        }
        if ($e instanceof ThrowableError) {
            header('Content-Type:application/json; charset=utf-8');
            exit(json_encode(['data' => '致命错误', 'code' => config('code.common.error')]));
        }
        return parent::render($e);
    }

}
